package com.gaotu.demo.jvm;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("thread")
public class ThreadController {
    @RequestMapping("oom/{loop}")
    public String oom(@PathVariable("loop") int loop){
        for (int i = 0; i< loop; i++){
            new Thread(new Task()).start();
        }
        return "SUCCESS";
    }

    static class Task implements Runnable{

        @Override
        public void run() {
            try {
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
